import ConfigParser 
  
cf = ConfigParser.ConfigParser() 
  
#read config 
cf.read("test.conf") 
  
# return all section 
secs = cf.sections() 
print 'sections:', secs 
  
opts = cf.options("sec_a") 
print 'options:', opts 
  
kvs = cf.items("sec_a") 
print 'sec_a:', kvs 

str_val = cf.get("sec_a", "a_key1") 
int_val = cf.getint("sec_a", "a_key2") 
  
print "value for sec_a's a_key1:", str_val 
print "value for sec_a's a_key2:", int_val 

cf.set("sec_b", "b_key3", "new-$r")
cf.write(open("test.conf", "w")) 
cf.write(open("test.conf", "w"))
